package logic

import (
	"context"
	"fmt"
	"wei-chat/models"

	"wei-chat/weichatrpc/internal/svc"
	"wei-chat/weichatrpc/weichatrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowLogic {
	return &ShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 个人信息
func (l *ShowLogic) Show(in *weichatrpc.ShowRequest) (*weichatrpc.ShowResponse, error) {
	// todo: add your logic here and delete this line

	var user models.User
	models.DB.Debug().Where("id = ?", in.UserId).Find(&user)
	if user.ID == 0 {
		return nil, fmt.Errorf("当前账号不存在,查找失败")
	}

	return &weichatrpc.ShowResponse{
		UserId:   int64(user.ID),
		Account:  user.Account,
		Password: user.Password,
		NickName: user.NickName,
		Image:    user.Image,
	}, nil
}
